/*******************************************************************************
 * Copyright (c) 2009 Kevin Bierhoff and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Kevin Bierhoff - initial API and implementation
 *******************************************************************************/
package com.googlecode.twelfdevtools.editor;

import org.eclipse.jface.text.rules.*;
import org.eclipse.jface.text.*;

public class TwelfScanner extends RuleBasedScanner {

	public TwelfScanner(ColorManager manager) {
		IToken constant =
			new Token(
				new TextAttribute(
					manager.getColor(ITwelfColorConstants.CONST)));
		IToken variable =
			new Token(
				new TextAttribute(
					manager.getColor(ITwelfColorConstants.VAR)));
		IToken comment =
			new Token(
				new TextAttribute(
					manager.getColor(ITwelfColorConstants.COMMENT)));
		IToken procInstr =
			new Token(
				new TextAttribute(
					manager.getColor(ITwelfColorConstants.PROC_INSTR)));
		IToken keyword =
			new Token(
				new TextAttribute(
					manager.getColor(ITwelfColorConstants.KEYWORD)));

		IRule[] rules = new IRule[11];
		
		int i = 0;
		// comments
		rules[i++] = new MultiLineRule("%{", "}%", comment);
		rules[i++] = new EndOfLineRule("%%", comment);
		
		//Add rule for processing instructions
		rules[i++] = new EndOfLineRule("%mode", procInstr);
		rules[i++] = new EndOfLineRule("%total", procInstr);
		rules[i++] = new EndOfLineRule("%block", procInstr);
		rules[i++] = new EndOfLineRule("%worlds", procInstr);
		rules[i++] = new EndOfLineRule("%name", procInstr);
		rules[i++] = new EndOfLineRule("%trustme", procInstr);
		
		rules[i++] = new WordRule(new TwelfVariableDetector(), variable);
		
		WordRule cr = new WordRule(new TwelfConstantDetector(), constant);
		cr.addWord("type", keyword);
		cr.addWord("_", variable);
		rules[i++] = cr;
		
		// Add generic whitespace rule.
		rules[i++] = new WhitespaceRule(new TwelfWhitespaceDetector());

		setRules(rules);
	}
}
